﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.Practices.Unity;

namespace Infrastructure.Aspect.Interceptor
{
    public class PerformanceInterceptor : ICallHandler
    {        
        private IUnityContainer ContainerService { get; set; }
        public PerformanceInterceptor(IUnityContainer container)
        {
            this.ContainerService = container;

        }
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            var ins = ContainerService.Resolve<Inspectors.IMethodAuditService>();
            var operation = Guid.NewGuid();
            ins.RegisterMethodAudit(input.MethodBase, operation); 
            var result = getNext()(input, getNext);
            ins.RegisterMethodAudit(input.MethodBase, operation);
            return result;
        }
        public int Order { get; set; }        
    }
}
